package com.liao.ten.article;

import android.view.View;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.os.Bundle;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.liao.ten.R;

import java.io.Serializable;
import java.util.ArrayList;

public class ItemArticleLayoutFragment extends Fragment {

    private TextView tvArticleTitle;
    private TextView tvArticleAuthor;
    private TextView tvArticleTimes;
    private TextView tvArticleSummary;
    private TextView tvArticleText;
    private TextView tvArticleAuthor1;
    private TextView tvArticleAuthorBrief;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.item_article_layout, null);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        tvArticleTitle = (TextView) view.findViewById(R.id.tv_article_title);
        tvArticleAuthor = (TextView) view.findViewById(R.id.tv_article_author);
        tvArticleTimes = (TextView) view.findViewById(R.id.tv_article_times);
        tvArticleSummary = (TextView) view.findViewById(R.id.tv_article_summary);
        tvArticleText = (TextView) view.findViewById(R.id.tv_article_text);
        tvArticleAuthor1 = (TextView) view.findViewById(R.id.tv_article_author1);
        tvArticleAuthorBrief = (TextView) view.findViewById(R.id.tv_article_authorBrief);

        Bundle bundle = getArguments();
        ArticleInfo.ResultBean resultBean = (ArticleInfo.ResultBean) bundle.getSerializable("data1");
        ArticleDetailInfo articleDetailInfo = (ArticleDetailInfo) bundle.getSerializable("data2");
        try {
            tvArticleTitle.setText(resultBean.getTitle());
            tvArticleAuthor.setText(articleDetailInfo.getAuthor());
            tvArticleTimes.setText(String.valueOf(articleDetailInfo.getTimes()));
            tvArticleSummary.setText(resultBean.getSummary());
            tvArticleText.setText(articleDetailInfo.getText());
            tvArticleAuthor1.setText(articleDetailInfo.getAuthor());
            tvArticleAuthorBrief.setText(articleDetailInfo.getAuthorbrief());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
